﻿using System;

namespace CustomerContactSystem.WebForms.Admin.Classifications {
    public partial class Edit : BasePage {
        protected void Page_Load(object sender, EventArgs e) {
            if (!IsValidPageRequest(true, true, "id")) {
                return;
            }

            GetClassification();
        }

        private void GetClassification() {
            var classificationId = int.Parse(Request.QueryString["id"]);
            var classification = EnquiryClassificationRepository.GetById(classificationId);

            if (classification == null) {
                return;
            }

            ClassificationName.Text = classification.Classification;
        }

        protected void SaveClassificationClick(object sender, EventArgs e) {
            if (!IsValidPageRequest(true, false, "id")) {
                return;
            }

            var classificationId = int.Parse(Request.QueryString["id"]);
            var classification = EnquiryClassificationRepository.GetById(classificationId);

            if (classification == null) {
                SaveClassificationResultMessage.Text = "Classification not found!";
                return;
            }

            classification.Classification = ClassificationName.Text;
            EnquiryClassificationRepository.Update(classification);

            Response.Redirect("~/Admin/Classifications/List.aspx");
        }
    }
}